package com.zifan.sever.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zifan.sever.bean.Employee;
import com.zifan.sever.bean.Salary;
import com.zifan.sever.service.IEmployeeService;
import com.zifan.sever.service.ISalaryService;
import com.zifan.sever.utils.RespBean;
import com.zifan.sever.utils.RespPageBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工套账
 * @author Zifan
 * @date 2021年05月23日22:49
 */
@RestController
@RequestMapping("/salary/sobcfg")
public class EmpSalaryController {
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "获取所有套账")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries(){
        return salaryService.list();
    }

    @ApiOperation("分页获取所有的员工带着套账")
    @GetMapping("/")
    public RespPageBean getEmpWithSalary(@RequestParam(defaultValue = "1")Integer currentPage,
                                         @RequestParam(defaultValue = "10") Integer size){
        return employeeService.getEmpWithSalary(currentPage,size);
    }

    @ApiOperation("更新员工套账信息")
    @PutMapping("/")
    public RespBean updateSalary(Integer eid,Integer sid){
        if (employeeService.update(new UpdateWrapper<Employee>().set("salaryId",sid).eq("id",eid))){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
